package main.FileVisitors.FileVisitorImpl;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;

import main.FileVisitors.MyFileVisitor;

public class SimpleFileVisitor extends MyFileVisitor {

    private int files = 0;
    private int folders = 0;
    private long totalSize = 0;

    public SimpleFileVisitor() {
    }

    public SimpleFileVisitor(String lookFor) {
        this.lookFor = lookFor;
    }

    @Override
    public FileVisitResult postVisitDirectory(Path arg0, IOException arg1) throws IOException {
        return FileVisitResult.CONTINUE;
    }

    @Override
    public FileVisitResult preVisitDirectory(Path arg0, BasicFileAttributes arg1) throws IOException {
        folders++;
        return FileVisitResult.CONTINUE;
    }

    @Override
    public FileVisitResult visitFile(Path arg0, BasicFileAttributes arg1) throws IOException {
        if (arg0.toString().contains(lookFor)) {
            matches.add(arg0);
        }
        files++;
        totalSize += (new File(arg0.toString())).length();
        return FileVisitResult.CONTINUE;
    }

    @Override
    public FileVisitResult visitFileFailed(Path arg0, IOException arg1) throws IOException {
        return FileVisitResult.CONTINUE;
    }

    @Override
    public int getFiles() {
        return files;
    }

    @Override
    public int getFolders() {
        return folders;
    }

    @Override
    public long getTotalSize() {
        return totalSize;
    }

    public void setFiles(int files) {
        this.files = files;
    }

    public void setFolders(int folders) {
        this.folders = folders;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }
}
